<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover">
  <title>Document</title>
  <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
  <style type="text/css">
    @font-face {
      font-family: 'cour';
      font-style: normal;
      font-weight: normal;
      font-display: auto;
      src: url('./cour.ttf') format('truetype');
    }
    * {
      padding: 0;
      margin: 0;
    }
    html, body {
      width: 100%;
      height: 100%;
    }
    html {
      font-family: fangsong;
      color: #fff;
    }
    body {
      display: flex;
      flex-direction: column;
    }
    .meinv-bg {
      width: 100%;
      height: 100%;
      background: url('../girl.jpg') no-repeat;
      background-position: center top;
    }
    .text-content {
      position: absolute;
      left: 0;
      right: 0;
      width: 100%;
      height: 100%;
      overflow-y: auto;
    }
    h1 {
      text-align: center;
      color: rgb(191, 229, 235);
      font-size: 50px;
    }
    select, input, textarea {
      font-family: fangsong;
      width: 250px;
      font-size: 20px;
      min-height: 30px;
      box-sizing: border-box;
      opacity: 0.9;
      border: none;
      outline: none;
      padding: 0 10px;
    }
    textarea {
      padding: 10px;
      resize: none;
    }
    .cell {
      display: flex;
      align-items: center;
      margin-bottom: 20px;
    }
    .cell label {
      margin-right: 20px;
      font-size: 20px;
      width: 150px;
    }
    .require label::after {
      content: '*';
      color: #e9f539;
    }

    .textarea-cell {
      align-items: flex-start;
    }

    .gan-btn {
      margin: 30px auto;
      display: block;
      color: #fff;
      outline: none;
      border: none;
      text-align: center;
      font-family: fangsong;
      cursor: pointer;
      background-color: rgb(255, 255, 0, 0.7);
      font-weight: 600;
    }

    #text {
      width: 100%;
      overflow-x: auto;
      white-space: nowrap;
      box-sizing: border-box;
    }
    
    /* 移动端样式 */
    @media only screen and (max-width: 750px) {
      h1 {
        font-size: 25px;
        margin: 30px 20px;
      }
      .cell-content {
        padding: 0 20px;
      }
      .cell {
        margin-bottom: 10px;
      }

      select, input, textarea {
        font-size: 16px;
        width: 200px;
        min-height: 25px;
      } 

      textarea {
        resize: none;
        height: 100px;
      }

      .cell label {
        font-size: 16px;
        width: 100px;
      }
      .gan-btn {
        width: 150px;
        height: 40px;
        border-radius: 8px;
        font-size: 24px;
      }
    }
    /* pc端样式 */
    @media only screen and (min-width: 760px) {
      .cell-content {
        display: flex;
        width: max-content;
        margin: 0 auto;
      }
      h1 {
        margin: 30px 50px 50px;
      }
      .left-cell {
        margin-right: 80px;
      }
      .right-cell {
        height: inherit;
      }
      .textarea-cell, .textarea-cell textarea {
        height: 100%;
      }
      .last-child {
        margin-bottom: 0;
      }
      .gan-btn {
        width: 300px;
        height: 50px;
        border-radius: 10px;
        font-size: 26px;
      }
      #text {
        padding: 20px 40px;
      }
    }
    
  </style>
</head>
<body>
    <div class="meinv-bg"></div>
    <div class="text-content">
      <h1>超级无敌棒棒糖</h1>
      <div class="cell-content">
        <div class="left-cell">
          <p class="cell require">
            <label>1、干</label>
            <select id="do">
              <option value="" style="display:none"></option>
              <option value="build">build</option>
              <option value="deploy">deploy</option>
              <option value="gogogo">gogogo</option>
            </select>
          </p>
      
          <p class="cell require">
            <label>2、运行环境</label>
            <select id="env">
              <option value="" style="display:none"></option>
              <option value="dev">dev</option>
              <option value="stag">stag</option>
              <option value="prod">prod</option>
            </select>
          </p>
      
          <p class="cell">
            <label>3、代码分支</label>
            <input id="branch" type="text">
          </p>
      
          <p class="cell">
            <label>4、发布版本</label>
            <input id="version" type="text">
          </p>
      
          <p class="cell">
            <label>5、灰度发布</label>
            <select id="gray">
              <option value="no">no</option>
              <option value="yes">yes</option>
            </select>
          </p>
      
          <p class="cell">
            <label>6、跳过测试</label>
            <select id="skiptest">
              <option value="no">no</option>
              <option value="yes">yes</option>
            </select>
          </p>
      
          <p class="cell">
            <label>7、强制构建</label>
            <select id="force">
              <option value="no">no</option>
              <option value="yes">yes</option>
            </select>
          </p>
      
          <p class="cell last-child">
            <label>8、项目类别</label>
            <select id="category">
              <option value="" style="display:none"></option>
              <option value="java">java</option>
              <option value="node">node</option>
              <option value="dockerfile">dockerfile</option>
            </select>
          </p>
        </div>
        <div class="right-cell">
          <p class="cell require textarea-cell">
            <label>9、项目列表</label>
            <textarea id="projects" cols="30" rows="10" placeholder="一个项目一行"></textarea>
          </p>
        </div>
      </div>
      <button class="gan-btn" onclick="start()">开 干</button>
      <div id="text"></div>
    </div>
    
  </div>
 <script>
  
  function start() {
    let doValue = $('#do option:selected').val()
    if (!doValue) return window.alert('请选择"干"')

    let env = $('#env option:selected').val()
    if (!env) return window.alert('请选择运行环境')

    let projects = $('#projects').val()
    if (!projects) return window.alert('请输入项目列表')

    $('#text').html('干ing....')
    $.ajax({
      type: 'POST',
      url: 'http://192.168.11.81:9527/hook/hand',
      data: JSON.stringify({
          do: doValue,
          env: env,
          branch: $('#branch').val(),
          version: $('#version').val(),
          gray: $('#gray option:selected').val() || '',
          skiptest: $('#skiptest option:selected').val() || '',
          force: $('#force option:selected').val() || '',
          category: $('#category option:selected').val() || '',
          projects: projects.split(/[\r\n]/)
      }),
      headers: {
        token: '123456',
        user: 'kevin',
        sec: 'aabbcc1234'
      },
      contentType: 'application/json',
      success: function (response) {
        let str = response
        str = str.replace(/ /g, '&nbsp;').replace(/[\r\n]/g, '<br/>').replace(/\[.*?m/g, '').replace(//g, '')
        console.log('str', str)
        $('#text').html(str)
      },
      // xhr是ajax对象
      error: function (xhr) {
        console.log('xhr', xhr)
        $('#text').html('干失败了')
      }
    });
  }
 </script>
</body>
</html>